import React, { useEffect, useState } from "react";
import Add from "./Couponsub/Add";
import Update from "./Couponsub/Update";
import Search from "./Couponsub/Search";
import List from "./Couponsub/List";
import { find } from "../../services/coupon";

export default function (props) {
    let [copuons, setCopuons] = useState([]);
    let [type,setType] = useState("");
    let [value,setValue] = useState("");
    let [pagination,setPagination] = useState({
        showQuickJumper:true,
        showSizeChanger:true,
        pageSizeOptions:[5,10,15,20,25],
        showTotal:total => `共 ${total} 条`
    });
    // let [isModalOpen, setIsModalOpen] = useState(false);
    const show = async (params = {}) => {
        if(params.type){
            setType(params.type);
            setValue(params.value);
        }else{
            params.type = type;
            params.value = value;
        }
        let data = await find(params);
        setCopuons(data.rows);
        data.current = parseInt(data.current);
        setPagination({...pagination,...data});
        console.log(data)
    };
    useEffect(() => {
        show();
    }, [""]);
    return (
        <div>
            <h1>优惠券</h1>
            <Add show={show} />
            <Update
                show={show}
            />
            <Search show={show} />
            <List
                pagination={pagination}
                show={show}
                copuons={copuons}
            />
            {/*

    */}
        </div>
    );
}
